package org.example.struct.array;

import java.util.Arrays;

/**
 * @author liyishan
 * @date 2023/8/21 09:40
 * @apiNote
 */

public class Test01013CanThreePartsEqualSum {
    public static void main(String[] args) {
        int[] arr = new int[]{1,-1,1,-1};
        System.out.println(test(arr));
    }

    public static boolean test(int[] arr) {
        if(Arrays.stream(arr).sum()%3 != 0 ){
            return false;
        }
        int sum = Arrays.stream(arr).sum()/3;
        int n = arr.length,i=0,cur = 0;
        while(i<n){
            cur +=arr[i];
            if(cur == sum){
                break;
            }
            i++;
        }
        if(cur != sum){
            return false;
        }
        int j = i+1;
        while (j + 1 < n) {
            cur += arr[j];
            if(cur == sum *2){
                return true;
            }
            j++;
        }
        return false;
    }


}
